/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utils.dispatchers;

import java.awt.KeyEventDispatcher;
import java.awt.event.KeyEvent;
import java.util.Observable;

/**
 *
 * @author Nobody
 */
public class KeyBoardDispatcher extends Observable implements KeyEventDispatcher {

    static KeyBoardDispatcher instance;

    private KeyBoardDispatcher() {
    }

    public static KeyBoardDispatcher getInstance() {
        if (instance == null) {
            instance = new KeyBoardDispatcher();
        }
        return instance;
    }
    private boolean isControlDown;
    private boolean isShiftDown;
    private boolean isAltDown;

    public boolean isIsAltDown() {
        return isAltDown;
    }

    public boolean isControlDown() {
        return isControlDown;
    }

    public boolean isShiftDown() {
        return isShiftDown;
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent e) {
        if (e.getID() == KeyEvent.KEY_PRESSED) {
            updateIndicators(e);
        } else if (e.getID() == KeyEvent.KEY_RELEASED) {
            updateIndicators(e);
        }
        return false;
    }

    private void updateIndicators(KeyEvent e) {
        isControlDown = e.isControlDown();
        isShiftDown = e.isShiftDown();
        isAltDown = e.isAltDown();
        setChanged();
        notifyObservers();
    }
}
